package com.h2psoft.truyen.tranh.adapter;

import java.util.ArrayList;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.h2psoft.truyen.tranh.activities.FragmentInComic;

public class AdapterFragment extends FragmentStatePagerAdapter {
	private ArrayList<String[]> listPagesUrls;
	private int pageCount = 0;

	public AdapterFragment(FragmentManager fm, ArrayList<String> arrPagesUrls) {
		super(fm);
		listPagesUrls = new ArrayList<String[]>();
		int size = arrPagesUrls.size();
		for (int i = 0; i < size; i++) {
			if (i % 2 == 0) {
				String[] imagesPerPage = { arrPagesUrls.get(i), arrPagesUrls.get(i + 1) };
				listPagesUrls.add(imagesPerPage);
			}
		}
		setPageCount(arrPagesUrls.size() / 2);
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
		notifyDataSetChanged();
	}

	public void setListPagesUrls(ArrayList<String[]> listPagesUrls) {
		this.listPagesUrls = listPagesUrls;
		notifyDataSetChanged();
	}

	public ArrayList<String[]> getListPagesUrls() {
		return listPagesUrls;
	}

	@Override
	public Fragment getItem(int arg0) {
		return FragmentInComic.newInstance(getListPagesUrls().get(arg0));
	}

	@Override
	public int getCount() {
		return pageCount;
	}

}
